/**
 * Copyright (c) 2018-2022, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 *
 * Contains: start for riscv64
 *
 * Change Logs:
 * Date           Author            Notes
 * 2022-05-01     JasonHu           Init
 */

#include <nxos_mini.h>

NX_IMPORT NX_Addr __NX_BssStart;
NX_IMPORT NX_Addr __NX_BssEnd;

NX_IMPORT int NX_Main(NX_UArch coreId);
NX_Size __firstBootMagic = 0x5a5a;

extern NX_Error NX_HalPlatformInit(NX_UArch coreId);

void NX_HalClearBSS(void)
{
    NX_UArch *dst;

    dst = &__NX_BssStart;
    while (dst < &__NX_BssEnd)
    {
        *dst++ = 0x00UL;
    }
}

void __NX_EarlyMain(NX_UArch coreId, NX_Addr sp)
{
    if (__firstBootMagic == 0x5a5a)
    {
        NX_HalClearBSS();
        __firstBootMagic = 0;
    }
    
#ifdef CONFIG_NX_HYPERVISOR_SUPPORT
    int currEL = Get_Current_El();
    NX_Printf("currrent el is at EL %d\n", currEL);
#endif
    NX_Main(coreId);
}
